package com.itheima.tlias84.controller;

import com.itheima.tlias84.mapper.ClazzMapper;
import com.itheima.tlias84.mapper.DeptMapper;
import com.itheima.tlias84.mapper.EmpMapper;
import com.itheima.tlias84.utils.ResultUtil;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
//@RequiredArgsConstructor(onConstructor = @__(@Autowired))
//@RequiredArgsConstructor(onConstructor_ = @Autowired)
@AllArgsConstructor
public class TestAutowiredController {
    /*
     * 两个注解的使用选择：
     * @Resource-->springboot类中需要注入很少其它类的bean对象时使用
     * @Autowired--> springboot类中需要注入很多其它类的bean对象时使用
     */
    EmpMapper empMapper;
    DeptMapper deptMapper;
    ClazzMapper clazzMapper;



    /**
     * 构造器赋值：多属性
     */
    @Autowired
    public TestAutowiredController(DeptMapper deptMapper, ClazzMapper clazzMapper, EmpMapper empMapper) {
        this.deptMapper = deptMapper;
        this.clazzMapper = clazzMapper;
        this.empMapper = empMapper;
    }

    /**
     * set方法赋值：单个属性赋值
     */
    @Autowired
    public void setEmpMapper(EmpMapper empMapper) {
        this.empMapper = empMapper;
    }

//    /**
//     * 构造器赋值:一个属性赋值
//     */
//    @Autowired
//    public TestAutowiredController(EmpMapper empMapper) {
//        this.empMapper = empMapper;
//    }

    @GetMapping("testCons")
    public ResultUtil query() {
        log.info("empMapper:{}", empMapper);
        log.info("deptMapper:{}", deptMapper);
        log.info("clazzMapper:{}", clazzMapper);
        return ResultUtil.success();
    }
}
